<template>
  <div>
    <!--条件筛选-->
    <TopFilter :list="topFilterList" :cols="3" :collapse="boolean" @filterChange="changeHandle" @onCollapse="collapseHandle"></TopFilter>
    <!--操作 -->
    <!-- <el-button size="small" type="primary" icon="el-icon-printer" @click="saveHandle">打印预览</el-button> -->
    <button-area :style="{ paddingLeft: '80px' }"></button-area>
     <div>
      <businessStatistics :data="patternData" />
    </div>
    <BasePrint ref="print" :data="printList" template="businessStatistics" />
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import businessStatistics from '@/pages/repair/queryStatistics/incomeStatistics/businessStatistics/businessStatistics.vue';
import moment from 'moment';
import { getStatistics1 } from '@/api/repair/queryStatistics/queryAccounts';
import { getBusinessOrderOld } from '@/api/repair/queryStatistics/incomeStatistics';
export default {
  name: 'businessStatisticsOld',
  components: {businessStatistics},
  mixins: [dictionary],
  data() {
    this.conf = { add: '新增', delete: '删除', edit: '编辑', show: '显示' };
    this.formData = null;
    return {
      topFilterList: this.createTopFilterList(),
      patternData:[],
      visible: false,
      visible1: false,
      dialogTitle: '',
      boolean:false,
      printList:[],
      isSelectColumn:false,
      handleType: '',
      formData: {},
      tableData: [],
      ids: []
    };
  },
  mounted() {
    // 分页
    this.FilterTable = this.$refs.table.$refs.pageTable;
  },
  methods: {
    createTopFilterList() {
      return [
        {
          type: 'DATE',
          dateType: 'month',
          label: '查询年月',
          fieldName: 'dCheckBegin',
          placeholder: '请选择时间',
          rules: [{ required: true, message: '请选查询年月', trigger: 'change' }]
        }
      ];
    },
    selectData(val) {
      this.tableData = val;
    },
    selectChangeHandle(val) {
      this.selectedRow = val;
    },
    async changeHandle() {
      let month = this.topFilterList.find(item => item.fieldName === 'dCheckBegin').initialValue;
      if (month >= moment(new Date()).format('YYYY-MM')) {
        return this.$notify.warning({ title: '提示信息', message: '只能选择小于当前的月份！' });
      }
      let beginDate = moment(month).format('YYYY-MM-01');
      let endDate = moment(beginDate).add(1, 'month').subtract(1, 'day').format('YYYY-MM-DD');
      let json = { beginDate: beginDate, endDate: endDate };
      let res = await getStatistics1(json);
      this.patternData = res.data;
      this.patternData['unit'] = beginDate + ' 至 ' + endDate;
      for (var item in this.patternData.YYSRQK) {
        this.patternData.YYSRQK[item] = this.patternData.YYSRQK[item]=='0.00'?'':this.patternData.YYSRQK[item];
      }
      for (var item in this.patternData.SBSP) {
        this.patternData.SBSP[item] = this.patternData.SBSP[item]=='0.00'?'':this.patternData.SBSP[item];
      }
      for (var item in this.patternData.JSQK) {
        this.patternData.JSQK[item] = this.patternData.JSQK[item]=='0.00'?'':this.patternData.JSQK[item];
      }
      for (var item in this.patternData.QKQK) {
        this.patternData.QKQK[item] = (this.patternData.QKQK[item]=='0.00'||this.patternData.QKQK[item]==0)?'':this.patternData.QKQK[item];
      }
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    async saveHandle(){
      let month = this.topFilterList.find(item => item.fieldName === 'dCheckBegin').initialValue;
      if (month >= moment(new Date()).format('YYYY-MM')) {
        return this.$notify.warning({ title: '提示信息', message: '只能选择小于当前的月份！' });
      }
      if (!month) {
        return this.$notify.warning({ title: '提示信息', message: '请选择查询年月！' });
      }
      let beginDate = moment(month).format('YYYY-MM-01');
      let endDate = moment(beginDate).add(1, 'month').subtract(1, 'day').format('YYYY-MM-DD');
      let json = { beginDate: beginDate, endDate: endDate };
      let res = await getStatistics1(json);
      if (res.resultCode == 200) {
        this.printList = res.data;
        for (var item in this.printList.SXQK) {
          this.printList.SXQK[item] = this.printList.SXQK[item]==0?'':this.printList.SXQK[item];
        }
        for (var item in this.printList.YYSRQK) {
          this.printList.YYSRQK[item] = this.printList.YYSRQK[item]=='0.00'?'':this.printList.YYSRQK[item];
        }
        this.printList['unit'] = beginDate + ' 至 ' + endDate;
        this.$refs.print.EXCUTE_PRINT();
      }
    },
    showHandler() {
      // 显示
      this.dialogTitle = `其他费用`;
      this.visible = true;
    },
    closeHandler(val, type) {
      // 关闭
      this.visible = val;
      if (type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    }
  }
};
</script>
<style lang="less" scoped></style>
